package naga.x.util;

import org.apache.mina.core.buffer.IoBuffer;

import com.alibaba.fastjson.JSON;

public class IoBufferWrapper {

	private IoBuffer buf;
	
	public IoBufferWrapper(IoBuffer buf) {
		this.buf = buf;
	}
	
	public IoBuffer buf() {
		return buf;
	}

	@Override
	public String toString() {
		try {
			int len = buf.remaining();
			byte[] bytes = new byte[len];
			buf.get(bytes);
			return JSON.parse(bytes).toString();
		} catch (Exception e) {}
		return "unparse::" + buf;
	}
	
}
